import 'package:flutter/material.dart';

class UserInfo with ChangeNotifier {
  String _name = '';
  String _avatar = '';
  String _mobile = '';
  String _mobile2 = '';
  String _shareRandomCode = '';
  int _medalNum = 0;
  int _memberId = 0;

  String _shopName = '';
  String _shopLogo = '';
  String _changeNumber = '';

  String get name => _name;
  String get avatar => _avatar;
  String get mobile => _mobile;
  String get mobile2 => _mobile2;
  String get shareRandomCode => _shareRandomCode;
  int get medalNum => _medalNum;
  int get memberId => _memberId;

  String get shopName => _shopName;
  String get shopLogo => _shopLogo;
  String get changeNumber => _changeNumber;

  setInfo(
      {String name = '',
      String avatar = '',
      String mobile = '',
      String shareRandomCode = '',
      int medalNum = 0,
      int memberId = 0,}) {
    //更新状态
    if (name != '') _name = name;
    if (avatar != '') _avatar = avatar;
    if (medalNum > 0) _medalNum = medalNum;
    if (memberId != 0) _memberId = memberId;
    if (shareRandomCode != '') _shareRandomCode = shareRandomCode;

    if (mobile != '') {
      _mobile = mobile;
      if (mobile.length >= 11) {
        _mobile2 = (mobile.substring(0, 3) + '****' + mobile.substring(7));
      }
    }
    notifyListeners();
  }

  setShopInfo({String shopName = '',
      String shopLogo = '', String changeNumber = ''}){
    if (shopName != '') _shopName = shopName;
    if (shopLogo != '') _shopLogo = shopLogo;
    if (changeNumber != '') _changeNumber = changeNumber;
    notifyListeners();
  }
}
